<template>
<!-- 借款单 -->
<section class="content-box">
  <div v-if="isshowList">
    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-form class="title cover">
        <h2>借款单</h2>
        <el-form-item>
          <el-button size="small" class="el-icon-plus" @click="handleAdd">&nbsp;新建&nbsp;</el-button>
        </el-form-item>
        <el-form-item>
          <el-button size="small" @click="search" class="el-icon-search">&nbsp;查询</el-button>
        </el-form-item>
      </el-form>
    </el-col>
    <!--列表-->
    <el-table class="indexList" v-if="borrowList" :data="borrowList" highlight-current-row  v-loading="loading" @row-dblclick="handleEdit" @cell-mouse-enter="cellMouseEnterFn" @cell-mouse-leave="cellMouseLeaveFn" style="width: 100%;" element-loading-text="正在加载中">
      <!-- <el-table-column label="序号" type="index" width="100" sortable>
      </el-table-column> -->
      <!-- <el-table-column prop="DocType" label="类型">
      </el-table-column> -->
      <el-table-column prop="Borrow_DocDate" label="日期" :formatter="formatDate" sortable>
      </el-table-column>
      <el-table-column prop="Borrow_DocNO" label="单号" sortable>
      </el-table-column>
      <el-table-column prop="Borrow_TotalBorrowMoney" label="金额" sortable>
      </el-table-column>
      <el-table-column prop="Borrow_Title" label="业务描述" min-width="200" show-overflow-tooltip>
      </el-table-column>
      <!-- <el-table-column prop="UserName" label="申请人">
      </el-table-column> -->
      <el-table-column prop="DocStatus" label="状态" sortable>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <!-- <el-button-group>
            <el-button size="small" @click.native="handleEdit(scope.$index, scope.row)">&#12288;编辑&#12288;</el-button>
            <el-button v-if="scope.row.DocStatus==='待审核'" size="small" @click.native="repeal(scope.$index, scope.row)">&#12288;撤销&#12288;</el-button>
            <el-button size="small" @click.native="checkflowRow(scope.$index, scope.row)">查看流程</el-button>
            <el-button size="small" @click.native="handleDel(scope.$index, scope.row)">&#12288;删除&#12288;</el-button>
            <el-button size="small" v-if="scope.row.AttachmentCount>0" class="icon iconfont icon-attachment"></el-button>
          </el-button-group> -->
          <div v-if="scope.row.Borrow_DocNO==mouse_enter_Borrow_DocNO">
          <!-- <div>  -->
            <div  v-if="scope.row.DocStatus==='待审核'" class="list-img" @click.stop="repeal(scope.$index, scope.row)">
              <!-- 撤销 -->
              <img class="common-icon" src="../../../static/content/images/Common/common-repeal.png" alt=""/>
            </div>
            <div v-if="scope.row.DocStatus!=='新建'" class="list-img" @click.stop="checkflowRow(scope.$index, scope.row)">
              <!-- 查看流程 -->
              <img class="common-icon" src="../../../static/content/images/Common/common-flow.png" alt=""/>
            </div>
            <div v-if="scope.row.DocStatus==='新建'" class="list-img" @click.stop="handleDel(scope.$index, scope.row)">
              <!-- 删除 -->
              <img class="common-icon" src="../../../static/content/images/Common/common-list-dele.png" alt=""/>
            </div>
            <div  v-if="scope.row.AttachmentCount>0" class="list-img">
              <!-- 附件 -->
              <img class="common-icon" src="../../../static/content/images/Common/common-attach.png" alt=""/>
            </div>
          </div>
        </template>
			</el-table-column>
		</el-table>

    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-pagination @current-change="changePage" layout="prev, pager, next" :page-size="rows" :current-page="currentPage" :total="total" style="float:right;">
      </el-pagination>
    </el-col>

		<!--流程图-->
		<el-dialog title="流程执行情况" :visible.sync="checkflowRowVisible" :modal-append-to-body="false" align="center">
			<el-table :data="docRowView" min-height="300" header-align="center" v-loading="docViewloading" element-loading-text="拼命刷新中...">
				<el-table-column property="PlanUser" label="操作人"></el-table-column>
				<el-table-column property="StepName" label="步骤名称"></el-table-column>
				<el-table-column property="OpDate" label="时间"></el-table-column>
				<el-table-column property="OpRemark" label="备注"></el-table-column>
			</el-table>
		</el-dialog>
	</div>
	<!--新建页面-->
	<div v-if="isshowAdd">
		<!-- 导航条 -->
		<div class="flex-top">
			<div>
				<i class="el-icon-arrow-left back" @click="addToBack"></i>
				<span style="font-size:20px;vertical-align:middle;margin:0 10px;">借款单</span>
				<!-- <small>
					<span>状态：</span>
					<el-tag type="success">新增</el-tag>
				</small> -->
			</div>
			<!-- 右侧 -->
			<div class="flex">
				<span class="wrapper cover">
          <el-button-group>
            <el-button size="small" @click="openUploadDialog">
              <i class="icon iconfont icon-shangchuan"></i>&nbsp;附件
            </el-button>        
            <el-button size="small" @click="addSave">
              <i class="icon iconfont icon-baocun"></i>&nbsp;保存
            </el-button>
            <el-button size="small" @click="addSubmit">
              <i class="icon iconfont icon-tijiao"></i>&nbsp;提交
            </el-button>
          </el-button-group>
				</span>
			</div>
		</div>
		<!-- 中部 -->
    <div class="flex-content">
      <main class="borrow main">
        <div class="main-left">
          <div v-if="DocNo">
            <h3>单号:</h3>
            <strong>{{DocNo}}</strong>
          </div>
          <div>
            <h3>日期：</h3>
            <div class="flex">
              <el-date-picker type="date" v-model="Borrow_DocDate" placeholder="选择日期">
              </el-date-picker>
            </div>
          </div>
        </div>
        <div class="main-right">
          <div class="left-form">
            <el-row>
              <el-col :span="12">
                <span class="ele-text">收款对方</span>
                <el-radio-group v-model="supplierRadio" class="ele-form" @change="checkRadio(supplierRadio)">
                  <el-radio :label="2">{{name}}</el-radio>
                  <el-radio :label="1">
                    <div class="supplier-wrapper">
                      <u @click="showDropDial" class="text-ellipsis">{{supplierSelect!=""&&supplierRadio==1?SupplyCodeToNameFn:"其他"}}</u>
                      <!-- <el-popover ref="popover4" placement="bottom" width="320" trigger="click">
                        <div style="height:305px;">
                          <el-select v-model="supplierSelect" class="ele-form" :class="{ 'show-drop': supplierRadio==1 }" @change="choiceSupplie(supplierSelect)" filterable placeholder="请选择供应商">
                            <el-option v-for="(item,index) in selecSupplier" :key="index" :value='item.Code' :label="item.Name">
                            </el-option>
                          </el-select>
                        </div>
                      </el-popover>                
                      <el-button ref="supplierRadioTwo" class="btn-no-border" v-popover:popover4></el-button>                   -->
                      <div v-show="isShowSupplierSelect" class="supplier-dialog-cover" @click="supplierRadio=2"></div>
                      <div v-show="isShowSupplierSelect" class="supplier-dialog-wrapper">
                        <div class="supplier-dialog-box">
                          <div>
                            <el-select v-model="supplierSelect" class="ele-form" :class="{ 'show-drop': supplierRadio==1 }" @change="choiceSupplie(supplierSelect)" filterable placeholder="请选择供应商">
                              <el-option v-for="(item,index) in selecSupplier" :key="index" :value='item.Code' :label="item.Name">
                              </el-option>
                            </el-select>
                          </div>
                          <i class="kx-arrow kx-arrow-up">
                            <em></em>
                            <span></span>
                          </i>
                        </div>
                      </div>                    
                    </div>
                  </el-radio>
                </el-radio-group>
              </el-col>
              <el-col :span="12" style="position:relative">
                <span class="ele-text">银行账号</span>
                <span v-if="rcvBank" type="primary" class="bankNum">
                  {{rcvBankAccount}}
                </span>              
              </el-col>
              <el-col :span="12">
                <span class="text-money">申请金额(含税)元</span>
                <input type="text" v-model="TotalBorrowMoney" @blur="doToFixedFn('TotalBorrowMoney')" @keyup="onlyNumBasicFn('TotalBorrowMoney')" class='applied'>
              </el-col>
              <el-col :span="12">
                <span class="ele-text">开户银行</span>
                <el-select v-model="rcvBank" class="ele-form" @change="bankChange(rcvBank)">
                  <el-option v-for="(items,index) in bankInfo" :key="index" :value="items.Code" :label="items.Bank">
                  </el-option>
                </el-select>
              </el-col>
              <el-col class="expense-title-wrapper">
                <span class="ele-text">业务描述</span>
                <el-input
                type="textarea"
                :rows="3"
                placeholder="请输入内容"
                v-model="Borrow_Title">
                </el-input>              
              </el-col>
            </el-row>
          </div>
          <div class="right-form">
          </div>
        </div>
      </main>
      <!--预算明细-->
      <div class="budget-two padding-size-10">
        <div style="padding:10px;">     
          <span><i class="icon iconfont icon-iconfontcolor52"></i> 预算明细</span>
          <!-- &#x3000;
          合计：<span class="Count">{{Count}}</span>&#12288;    -->
          <!-- <el-button class="add-button" size="small" @click="addlist">添加行</el-button> -->
        </div>
        <table class="cusTable" border="1" width="100%">
          <tr>
            <!-- <th>操作</th>
            <th>金额</th>
            <th>费用承担部门</th>
            <th>费用类型</th>
            <th>预算余额</th> -->
            <th>操作</th>
            <th>费用承担部门</th>
            <th colspan="2">费用类型</th>
            <th>报销金额</th>            
          </tr>
          <tr v-for="(i,index) in detail" :key="index" class="cusTable-tr">
            <td width="10%">
              <!-- <el-button size="small" @click="handleDelete(index)" type="danger" class="dele">删除</el-button> -->
              <div class="oper-btn-wrapper">
                <button size="small" @click="handleDelete(index)" class="oper-btn"><img class="common-icon" src="/static/content/images/Common/common-dele.png"/></button>
                <button size="small" @click="addlist" class="oper-btn"><img class="common-icon" src="/static/content/images/Common/common-add.png"/></button>
              </div>
            </td>
            <td width="20%">
              <!-- 页面进来时 已经执行了这里绑定的 changeSelect -->
              <el-select class="formVal full-box" v-model="i.YBL_Department" @visible-change="changeSelect(index,i.YBL_Department,$event)">
                <!-- v-model => 费用承担部门 -->
                <el-option v-for="(item,index) in bears" :value="item.CODE" :key="index" :label="item.FULLNAME">
                </el-option>
              </el-select>
            </td>
            <td width="35%">
              <!-- BorrowLine_YBL 费用类型ID -->
              <el-select class="formVal full-box" @change="ChangeMoney(index)" v-model="i.BorrowLine_YBL" style="width:99%">   
                <el-option v-for="(item,index) in i.costTypes" :value="item.ID" :key="item.ID" :label="item.BudgetItem_Name">
                </el-option>
              </el-select>
            </td>
            <td width="15%" class="font-budgetBalance">
              <span class="budgetBalance">余额：{{i.balance}}</span>
              <!-- 预算金额 -->
            </td>
            <td>
              <el-input type="text" v-model="i.BorrowLine_BorrowMoney" @blur="doToFixed(i,'BorrowLine_BorrowMoney')" @keyup.native="onlyNumObjFn(i,'BorrowLine_BorrowMoney')" @keydown.enter.native="addlist" class="formval-money full-box" :placeholder="'请输入金额'"></el-input>
              <!-- v-model => 金额 -->
            </td>
          </tr>
        </table>
        <div class="clearfloat">
          <div class="total-box">合计：<span class="Count-text">{{Count}}</span></div>
        </div>         
      </div>
    </div>
	</div>
	<!-- 
		编辑/待审核/已审核/已发起/未发起 界面 		
	-->
	<div v-if="isshowEdit">
		<!-- 导航条 -->
		<div class="flex-top">
			<div>
				<i class="el-icon-arrow-left back" @click="editToBack"></i>
				<span style="font-size:20px;vertical-align:middle;margin:0 10px;">
					借款单</span>
				<small>
					<span>状态：</span>
					<el-tag type="success">{{Type===0?'新建':Type===1?'修改':Type===2?'查看':Type===3?'待审核':''}}</el-tag>
				</small>
			</div>
			<!-- 右侧 -->
			<div class="flex">    
				<span class="wrapper cover">
          <!-- <el-button-group>
            <el-button size="small" @click="openUploadDialog">
              <i class="icon iconfont icon-shangchuan"></i>&nbsp;附件
            </el-button>
            <el-button size="small" v-if="Type===3"  @click="auditBorrow">
              <i class="icon iconfont icon-shenhe"></i>&nbsp;审核
            </el-button>
            <el-button size="small" v-if="Type===3"  @click="rejectBorrow">
              <i class="icon iconfont icon-bohui"></i>&nbsp;驳回
            </el-button>
            <el-button size="small"  @click="Communication">
              <i class="icon iconfont icon-chat-with-doctor"></i>&nbsp;沟通
            </el-button>
            <el-button size="small"  @click="checkflow">
              <i class="icon iconfont icon-liucheng"></i>&nbsp;查看流程
            </el-button>
            <el-button size="small"  @click="editSave" :disabled="Type===2||Type===3">
              <i class="icon iconfont icon-baocun"></i>&nbsp;保存
            </el-button>
            <el-button size="small"  @click="editSubmit" :disabled="Type===2||Type===3">
              <i class="icon iconfont icon-tijiao"></i>&nbsp;提交
            </el-button>
            <el-button size="small" @click="getPrint">
              <i class="icon iconfont icon-yy"></i>&nbsp;打印
            </el-button>
          </el-button-group> -->
          <el-button-group>
            <el-button size="small" @click="openUploadDialog" :disabled="fjBtnDisabled">
              <i class="icon iconfont icon-shangchuan"></i>&nbsp;附件
            </el-button>
            <el-button size="small" v-if="Type!==0"  @click="Communication" :disabled="communicateButtonDisabled">
              <i class="icon iconfont icon-chat-with-doctor"></i>&nbsp;沟通
            </el-button>
            <el-button size="small" v-if="Type===2||Type===3"  @click="checkflow">
              <i class="icon iconfont icon-liucheng"></i>&nbsp;流程
            </el-button>
            <el-button size="small" v-if="Type===3"  @click="rejectBorrow">
              <i class="icon iconfont icon-bohui"></i>&nbsp;驳回
            </el-button>
            <el-button size="small"  @click="editSave" v-if="Type===0||Type===1" :disabled="Type===2||Type===3">
              <i class="icon iconfont icon-baocun"></i>&nbsp;保存
            </el-button>
            <el-button size="small"  @click="editSubmit" v-if="Type===0||Type===1" :disabled="Type===2||Type===3">
              <i class="icon iconfont icon-tijiao"></i>&nbsp;提交
            </el-button>
            <el-button size="small" @click="getPrint" v-if="Type===2">
              <i class="icon iconfont icon-yy"></i>&nbsp;打印
            </el-button>
            <el-button size="small" v-if="Type===3"  @click="auditBorrow">
              <i class="icon iconfont icon-shenhe"></i>&nbsp;同意
            </el-button>
          </el-button-group>
				</span>
			</div>
      <!-- 沟通 -->
      <!-- <el-dialog
        :visible.sync="dialogCommunicationVisible"
        :modal-append-to-body="false"
        size="tiny">
        <ul class="Communication" ref="content">
          <li v-for="(item,index) in CommunicationContentList" :key="index">
            <el-row>
              <el-col :span="2">
                <a href="javascript:;"><img :src="item.Img" alt="" class="round"/></a>
              </el-col>

              <el-col :span="22">              
                <div class="message1">
                  <p class="name"><el-tag type="success">{{item.CreateByName}}</el-tag></p>       
                  <p class="content">{{item.CC_Content}}</p>
                  <p class="date"><el-tag type="primary">{{item.SysCreateDate}}</el-tag></p>
                </div>
              </el-col>
            </el-row>
          </li>
          <li v-if="this.CommunicationContentList.length==0"><p class="not-communication"><i class="el-icon-warning"></i>未有沟通</p></li>
        </ul>
        <el-row v-if="this.communiTypes===3">
          <el-col :span="17">
            <el-select v-model="launch" multiple filterable="" allow-create placeholder="请选择沟通对象" style="width:80%;">
              <el-option v-for="(item,index) in LaunchList" :key="index" :label="item.RealName" :value="item.Id">
              </el-option>
            </el-select>
          </el-col>
          <el-col :span="2">
            <el-checkbox v-model="launchChecked" @change="launchChange(launchChecked)">允许提交者编辑单据</el-checkbox>
          </el-col>
        </el-row>
        <el-row v-if="(this.communiTypes!==0 && this.communiTypes!==2) || this.isshowLauch==true">
          <el-col :span="21">
            <el-input v-model="contentInput" placeholder="请输入内容"></el-input>
          </el-col>
          <el-col :span="2">          
            <el-button style="margin-left:10px;" type="primary" @click="CommunicationDetermine">发送</el-button>
          </el-col>          
        </el-row>
      </el-dialog> -->
      <!-- 沟通改版 -->
      <el-dialog
        class="el-dialog__body-padding"
        :visible.sync="dialogCommunicationVisible"
        :modal-append-to-body="false"
        size="tiny"
        style="line-height: normal;">
        <p v-if="CommunicationContentList.length!==0" class="title">沟通内容:</p>
        <ul v-if="CommunicationContentList.length!==0" class="Communication-Two mt-15 mb-15" ref="content">
          <li v-for="(item,index) in CommunicationContentList" :key="index" :class="index!==CommunicationContentList.length-1?'mb-10':''">
            <el-row>
              <el-col :span="4" class="Communication-left">
                <a href="javascript:;"><img :src="item.Img" alt="" class="round"/></a>
                <p class="name" style="color: #13ce66;">{{item.CreateByName}}</p>
              </el-col>
              <el-col :span="20" style="height: 78px;">              
                <div class="message1">      
                  <p class="content">{{item.CC_Content}}</p>
                  <p class="date"><el-tag type="primary">{{item.SysCreateDate}}</el-tag></p>
                </div>
              </el-col>
            </el-row>
          </li>
          <!-- <li v-if="this.CommunicationContentList.length==0"><p class="not-communication"><i class="el-icon-warning"></i>未有沟通</p></li> -->
        </ul>
        <p v-if="communiTypes===3" class="title">发起沟通:</p>
        <el-row v-if="communiTypes===3" class="padding-top-15">
          <el-col :span="17">
            <el-select v-model="launch" multiple filterable="" allow-create placeholder="请选择沟通对象" style="width:80%;">
              <el-option v-for="(item,index) in LaunchList" :key="index" :label="item.RealName" :value="item.Id">
              </el-option>
            </el-select>
          </el-col>
          <el-col :span="2">
            <el-checkbox v-model="launchChecked" @change="launchChange(launchChecked)">允许提交者编辑单据</el-checkbox>
          </el-col>
        </el-row>
        <!-- <el-row v-if="(this.communiTypes!==0 && this.communiTypes!==2) || this.isshowLauch==true">
          <el-col :span="21">
            <el-input v-model="contentInput" placeholder="请输入内容"></el-input>
          </el-col>
          <el-col :span="2">          
            <el-button style="margin-left:10px;" type="primary" @click="CommunicationDetermine">发送</el-button>
          </el-col>          
        </el-row> -->
        <!-- <p v-if="(this.communiTypes!==0 && this.communiTypes!==2) || this.isshowLauch==true" v-show="this.CommunicationContentList.length!==0" class="title padding-top-15">回复沟通:</p> -->
        <div v-if="(this.communiTypes!==0 && this.communiTypes!==2) || this.isshowLauch==true" v-show="this.CommunicationContentList.length!==0">
          <p v-if="this.communiTypes!==3" class="title padding-top-15">回复沟通:</p>
        </div>
        <el-row v-if="(this.communiTypes!==0 && this.communiTypes!==2) || this.isshowLauch==true" class="padding-top-15">
          <el-col :span="24">
            <el-input v-model="contentInput" type="textarea" :rows="3" placeholder="请输入内容"></el-input>
          </el-col>     
        </el-row>
        <el-row v-if="(this.communiTypes!==0 && this.communiTypes!==2) || this.isshowLauch==true" class="padding-top-15">
          <el-col :span="24">          
            <el-button style="float: right;" type="primary" @click="CommunicationDetermine">发送</el-button>
          </el-col>          
        </el-row>
      </el-dialog>     
      <!--流程图-->
			<el-dialog title="流程执行情况" :visible.sync="checkflowVisible" :modal-append-to-body="false" align="center">
				<el-table :data="docView" header-align="center" v-loading="docViewloading" element-loading-text="拼命刷新中...">
					<el-table-column property="PlanUser" label="操作人"></el-table-column>
					<el-table-column property="StepName" label="步骤名称"></el-table-column>
					<el-table-column property="OpDate" label="时间"></el-table-column>
					<el-table-column property="OpRemark" label="备注"></el-table-column>
				</el-table>
			</el-dialog>

			<!--
				打印窗口
			-->
			<el-dialog :visible.sync="dialogPrintVisible" :modal-append-to-body="false">
				<div class="printBox cover">
					<el-button size="small" class="center" @click.native="printPdf()">&#12288;打印&#12288;</el-button>
					<div id="form1">
            <table width="100%" border="0" v-loading="PrintLoading" element-loading-text="正在加载中">
              <caption>
                <h3 id="Doc">{{printsData.ER_Tite || ''}}</h3>
              </caption>
              <thead>
                <tr>
                  <td style="padding:15px 10px;line-height:30px;">
                    <div id="CompanyName" style="float:left">{{printsData.CompanyName || ''}}</div>
                    <div id="Current" style="float:right">打印日期：{{printsData.Current || ''}}</div>
                  </td>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td>
                    <div id="div" class="table-c">
                      <table cellpadding="3" width="100%" class="ListTable">
                        <tbody>
                          <tr>
                            <td class="tbTitle">单号</td>
                            <td class="Tabletd">{{printsData.entity ? printsData.entity.DocNo : '' }}</td>
                            <td class="tbTitle">申请人</td>
                            <td class="Tabletd">{{printsData.entity ? printsData.entity.CreateByName : ''}}</td>
                            <td class="tbTitle">申请部门</td>
                            <td class="Tabletd">{{printsData.entity ? printsData.entity.RequestDeptName : ''}}</td>
                          </tr>
                          <tr>
                            <td class="tbTitle">单据日期</td>
                            <td class="Tabletd">{{printsData.entity ? printsData.entity.DocDateStr : ''}}</td>
                            <td class="tbTitle">业务类型</td>
                            <td class="Tabletd">{{printsData.entity.BusinessType==2?`对私`:`对公`}}</td>
                            <td class="tbTitle">供应商</td>
                            <td class="Tabletd">{{printsData.entity ? printsData.entity.SupplierName : ''}}</td>
                          </tr>
                          <tr>
                            <td class="tbTitle">借款金额</td>
                            <td class="Tabletd">{{printsData.entity && printsData.entity.TotalBorrowMoney ? printsData.entity.TotalBorrowMoney.toFixed(2) : '0.00'}}</td>
                            <td class="tbTitle">开户银行</td>
                            <td class="Tabletd">{{printsData.entity ? printsData.entity.RcvBank : ''}}</td>
                            <td class="tbTitle">银行账号</td>
                            <td class="Tabletd">{{printsData.entity ? printsData.entity.RcvBankAccount : ''}}</td>
                          </tr>
                          <tr>
                            <td class="tbTitle">业务描述</td>
                            <td colspan="5" class="Tabletd">
                              {{printsData.entity ? printsData.entity.Title : ''}}
                            </td>
                          </tr>
                        </tbody>
                      </table>
                    </div>
                  </td>
                </tr>
                <tr>
                  <td style="line-height:30px;">&nbsp;</td>
                </tr>
                <tr>
                  <td>
                    <div id="Line" class="table-c">
                      <table width="100%" class="ListTable">
                        <thead>
                          <tr>
                            <td width="5%">NO</td>
                            <td>预算树</td>
                            <td>预算组织</td>
                            <td>预算科目</td>
                            <td>借款金额</td>
                          </tr>
                        </thead>
                        <tbody>
                          <tr v-for="(p,index) in printsData.entity.BorrowLineSet" :key="index">
                            <td>{{index+1}}</td>
                            <td>{{p.YBDEntity.YearBudgetName ? p.YBDEntity.YearBudgetName : ''}}</td>
                            <td>{{p.YBDEntity.DepartmentName ? p.YBDEntity.DepartmentName : ''}}</td>
                            <td>{{p.YBDEntity.BudgetItemName ? p.YBDEntity.BudgetItemName : ''}}</td>
                            <td>{{p && p.BorrowMoney ? p.BorrowMoney.toFixed(2) : ''}}</td>
                          </tr>
                          <tr>
                            <td colspan="4">合计</td>
                            <td>{{printsData.entity && printsData.entity.BorrowLineSetMoney ? printsData.entity.BorrowLineSetMoney.toFixed(2):'0.00'}}</td>
                          </tr>
                        </tbody>
                      </table>
                    </div>
                  </td>
                </tr>
                <tr>
                  <td style="line-height:30px;">&nbsp;</td>
                </tr>
                <tr>
                  <td>
                    <div id="Line" class="table-c">
                      <table width="100%" class="ListTable">
                        <thead>
                          <tr>
                            <td width="5%">NO</td>
                            <td>处理人</td>
                            <td>处理结果</td>
                            <td>备注</td>
                            <td>处理日期</td>
                          </tr>
                        </thead>
                        <tbody>
                          <tr v-for="(p,index) in printsData.Chart" :key="index">
                            <td>{{index+1}}</td>
                            <td>{{p.PlanUser ? p.PlanUser : ''}}</td>
                            <td>{{p.StepName ? p.StepName : ''}}</td>
                            <td>{{p.OpRemark ? p.OpRemark : ''}}</td>
                            <td>{{p.OpDate ? p.OpDate : ''}}</td>
                          </tr>
                        </tbody>
                      </table>
                    </div>
                  </td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <!--审批流-->
                  <td>
                    <div id="Chart" class="table-c"></div>
                  </td>
                </tr>
              </tbody>
            </table>
					</div>
				</div>
			</el-dialog>
		</div>
    <div class="flex-content">
      <!-- 中部 -->
      <main class="borrow main">
        <div class="main-left">
          <div>
            <h3>单号:</h3>
            <strong>{{DocNo}}</strong>
          </div>
          <div>
            <h3>日期</h3>
            <div class="flex">
              <el-date-picker type="date" placeholder="选择日期" :disabled="Type===2 || Type===3" v-model="Borrow_DocDate">
              </el-date-picker>
            </div>
          </div>
        </div>
        <div class="main-right">
          <div class="left-form">
            <el-row>
              <el-col :span="12">
                <span>收款对方</span>
                <el-radio-group v-model="supplierRadio" style="margin-left:20px;" :disabled="Type===2||Type===3"  @change="checkRadio(supplierRadio)">
                  <el-radio :label="2">{{name}}</el-radio>								
                  <el-radio :label="1">
                    <div class="supplier-wrapper">
                      <u v-if="Type!==2 && Type!==3" @click="showDropDial" class="text-ellipsis">{{supplierSelect!=""&&supplierRadio==1?SupplyCodeToNameFn:"其他"}}</u>
                      <u v-if="Type===2 || Type===3" class="text-ellipsis">{{supplierSelect!=""&&supplierRadio==1?SupplyCodeToNameFn:"其他"}}</u>
                      <!-- <el-popover ref="popover4" placement="bottom" width="320" trigger="click">
                        <div style="height:305px;"> -->
                          <!-- <el-select v-model="supplierSelect" class="ele-form" :class="{ 'show-drop': supplierRadio==1 }" @change="choiceSupplie(supplierSelect)" filterable placeholder="请选择供应商">
                            <el-option v-for="(item,index) in selecSupplier" :key="index" :value='item.Code' :label="item.Name">
                            </el-option>
                          </el-select> -->
                          <!-- <el-select v-model="supplierSelect" class="ele-form" :class="{ 'show-drop': supplierRadio==1 }" @change="choiceSupplie(supplierSelect)" filterable placeholder="请选择供应商">
                            <el-option v-for="(item,index) in selecSupplier" :key="index" :value='item.Code' :label="item.Name">
                            </el-option>
                          </el-select>
                        </div>
                      </el-popover>                
                      <el-button ref="supplierRadioTwo" class="btn-no-border" v-popover:popover4></el-button>-->
                      <div v-show="isShowSupplierSelect" class="supplier-dialog-cover" @click="supplierRadio=2"></div>
                      <div v-show="isShowSupplierSelect" class="supplier-dialog-wrapper">
                        <div class="supplier-dialog-box">
                          <div>
                            <el-select v-model="supplierSelect" class="ele-form" :class="{ 'show-drop': supplierRadio==1 }" @change="choiceSupplie(supplierSelect)" filterable placeholder="请选择供应商">
                              <el-option v-for="(item,index) in selecSupplier" :key="index" :value='item.Code' :label="item.Name">
                              </el-option>
                            </el-select>
                          </div>
                          <i class="kx-arrow kx-arrow-up">
                            <em></em>
                            <span></span>
                          </i>
                        </div>
                      </div>
                    </div>                     
                  </el-radio>
                </el-radio-group>
              </el-col>
              <!-- <el-col :span="12">
                <span>供应商</span>
                <el-select v-model="supplierSelect" filterable style="margin-left:20px;" :disabled="Type===2||Type===3" @change="choiceSupplie(supplierSelect)">
                  <el-option v-for="(item,index) in selecSupplier" :key="index" :value='item.Code' :label="item.Name">
                  </el-option>
                </el-select>
              </el-col> -->
              <el-col :span="12" style="position:relative">
                <span>银行账号</span>
                <span v-if="rcvBank" type="primary" class="bankNum">
                  {{rcvBankAccount}}
                </span>
              </el-col>
              <el-col :span="12">
                <span class="text-money">申请金额(含税)元</span>
                <input type="text" v-model="TotalBorrowMoney" @blur="doToFixedFn('TotalBorrowMoney')" @keyup="onlyNumBasicFn('TotalBorrowMoney')" class='applied'  :disabled="Type===2 || Type===3">
              </el-col>                        
              <el-col :span="12">
                <span>开户银行</span>
                <el-select v-model="rcvBank" style="margin-left:20px;" :disabled="Type===2||Type===3"  @change="bankChange(rcvBank)">
                  <el-option v-for="(items,index) in bankInfo" :key="index" :value="items.Code" :label="items.Bank">
                  </el-option>
                </el-select>
              </el-col>
              <el-col :span="24" class="expense-title-wrapper">
                <span class="ele-text">业务描述</span>
                <el-input
                  class="textarea-title"
                  type="textarea"
                  :rows="3"
                  placeholder="请输入内容"
                  v-model="Borrow_Title"
                  :disabled="Type===2||Type===3">
                </el-input>              
              </el-col>
            </el-row>
          </div>
          <div class="right-form"></div>
        </div>
      </main>
      <!--预算明细-->
      <div class="budget-two padding-size-10">
        <div style="padding:10px;">
          <span><i class="icon iconfont icon-iconfontcolor52"></i> 预算明细</span>
          <!-- &#x3000;
          合计：<span class="Count-text">{{Count}}</span>       -->
          <!-- <el-button class="add-button" size="small" @click="addlist">添加行</el-button>				 -->
        </div>
        <table class="cusTable" border="1" width="100%">
          <tr>
            <!-- <th>金额</th>
            <th>费用承担部门</th>
            <th>费用类型</th>
            <th>预算余额</th>
            <th>操作</th> -->
            <th>操作</th>
            <th>费用承担部门</th>
            <th colspan="2">费用类型</th>
            <th>报销金额</th>
          </tr>
          <tr v-for="(i,index) in detail" :key="index" class="cusTable-tr">
            <!-- 遍历初始化的detail添加行空数据 -->
            <td width="10%">
              <div class="oper-btn-wrapper">
              <!-- <el-button size="small" @click="handleDelete(index)" type="danger" class="dele" :disabled="Type===2||Type===3">删除</el-button> -->
                <button v-if="!(Type===2||Type===3)" size="small" @click="handleDelete(index)" class="oper-btn"><img class="common-icon" src="/static/content/images/Common/common-dele.png"/></button>
                <button v-if="!(Type===2||Type===3)" size="small" @click="addlist" class="oper-btn"><img class="common-icon" src="/static/content/images/Common/common-add.png"/></button>
              </div>
            </td>
            <td width="20%">
              <el-select class="formVal full-box" v-model="i.YBL_Department" @visible-change="changeSelect(index,i.YBL_Department,$event)" :disabled="Type===2||Type===3">
                <!-- v-model => 费用承担部门 -->
                <el-option v-for="(item,index) in bears" :value="item.CODE" :key="index" :label="item.FULLNAME">
                </el-option>
              </el-select>
            </td>
            <td width="35%">
              <el-select class="formVal full-box" @change="ChangeMoney(index)" v-model="i.BorrowLine_YBL" :disabled="Type===2||Type===3" style="width:99%">
                <!-- v-model => 费用类型 -->
                <el-option v-for="(item,index) in i.costTypes" :value="item.ID" :key="item.ID" :label="item.BudgetItem_Name">
                </el-option>
              </el-select>
            </td>
            <td width="15%" class="font-budgetBalance">
              <span class="budgetBalance">余额：{{i.balance}}</span>
              <!-- 预算金额 -->
            </td>
            <td>
              <el-input type="text" v-model="i.BorrowLine_BorrowMoney" @blur="doToFixed(i,'BorrowLine_BorrowMoney')" @keyup.native="onlyNumObjFn(i,'BorrowLine_BorrowMoney')" @keydown.enter.native="addlist" class="formval-money full-box" :disabled="Type===2||Type===3" :placeholder="'请输入金额'"></el-input>
              <!-- v-model => 金额 -->
            </td>
          </tr>
        </table>
        <div class="clearfloat">
          <div class="total-box">合计：<span class="Count-text">{{Count}}</span></div>
        </div>        
      </div>
    </div>    
	</div>
  <el-dialog title="超预算提醒" :visible.sync="budgetVisible" :modal-append-to-body="false" v-loading="loading" :show-close="false" :close-on-click-modal="false" :close-on-press-escape="false">
          超预算<strong>{{this.budgetMoney}}</strong>元，无法提交。请选择你的操作
          <el-tabs v-model="activeName" type="card" @tab-click="handleClick" style="line-height:42px;margin-top:20px;">
            <el-tab-pane label="撤销单据" name="first">
              <el-button type="primary" size="small" @click.native="repealBudget">确定</el-button>
            </el-tab-pane>
            <el-tab-pane label="追加预算" name="second">
              <el-input type="textarea" v-model="abstract1" placeholder="请输入追加理由......." :rows="5"></el-input>
              <el-button type="primary" size="small" @click.native="Supplementarybudget">确定</el-button>
            </el-tab-pane>
            <el-tab-pane label="互调预算" name="third">
              <el-input type="textarea" v-model="abstract2" placeholder="请输入追加理由......." :rows="5"></el-input>
              <span v-for ="(item, index) in templ" :key="index">
                {{item.trr}}
                <br>
                <el-radio-group v-model="item.radio" @change="budgetChangeRadio(item.radio,index)">
                  <el-radio :label="1">不同月之间调整 </el-radio>
                  <el-radio :label="2">不同部门之间调整 </el-radio>
                  <el-radio :label="3">不同科目之间调整 </el-radio>
                </el-radio-group>
                <el-select v-model="item.value" placeholder="请选择" @change="budgetChangeSelect(index,item.value)" style="margin-left:20px;">
                  <el-option v-for="(ite,index) in budgetitem[index]" :key="index" :label="ite.Name" :value="ite.Code?ite.Code:ite.ID">
                  </el-option>
                </el-select>          
                <br>
              </span>
              <el-button type="primary" size="small" @click="Intermodulationbudget">确定</el-button>              
            </el-tab-pane>
          </el-tabs>
  </el-dialog>
  <!--附件-->
  <el-dialog title="附件" :visible.sync="dialogUploadVisible" :modal-append-to-body="false" >
        <label for="file" class="label-file" v-if="Type!=2&&Type!=3"><i class="icon iconfont icon-shangchuan">&nbsp;</i>上传</label>
        <input name="file" id="file" type="file" accept="*" @change="update" multiple/>
        <div><br></div>
        <ul ref="images" style="display:none" >
          <li v-for="(item, index) in UploadList" :key="index">
            <!-- <img :src="`http://192.168.1.188:8011/${item.Attachment_Url}`" :alt="item.Attachment_FileName"> -->
            <img :src="item.Attachment_Url" :alt="item.Attachment_FileName">
          </li>
        </ul>
        <el-table :data="UploadList" header-align="center" id="test">
          <el-table-column property="ID" label="ID" width="100"></el-table-column>
          <el-table-column property="Attachment_UploadDate" label="日期" :formatter="formatUploadDate"></el-table-column>
          <el-table-column property="Attachment_FileName" label="名称" show-overflow-tooltip></el-table-column>          
          <el-table-column label="操作" max-width="100">
            <template slot-scope="scope">
              <div style="display:inline-block;">
                <el-button v-if='isShowPreview(scope.row.Attachment_FileName)' type="info" size="small" @click="preview(scope)">
                  &#12288;<i class="el-icon-search"></i>预览&#12288;
                </el-button>
              </div>
              <a class="down" :href="scope.row.Attachment_Url" :download='scope.row.Attachment_FileName'>下载</a>
              <el-button type="danger" v-if="Type!=2&&Type!=3" size="small" @click="DeleUpload(scope.$index, scope.row)">&#12288;删除&#12288;</el-button>
            </template>
          </el-table-column>
        </el-table>
  </el-dialog>
  <!--查询-->
  <el-dialog title="查询" :visible.sync="dialogSearchVisible" :modal-append-to-body="false" size="tiny">
    <el-form :model="Searchform">
      <el-form-item label="金  额 ：" :label-width="formLabelWidth">
        <el-input v-model.number.trim="Searchform.StartMoney" auto-complete="off" style="width:120px;"></el-input>
        至&nbsp;<el-input v-model.number.trim="Searchform.EndMoney" auto-complete="off" style="width:120px;"></el-input>
      </el-form-item>
      <el-form-item label="日  期 ：" :label-width="formLabelWidth">
        <el-date-picker type="date" v-model="Searchform.StartDate" style="width:120px;" placeholder="选择日期"></el-date-picker>
        至&nbsp;<el-date-picker type="date" v-model="Searchform.EndDate" style="width:120px;" placeholder="选择日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="单  号 ：" :label-width="formLabelWidth">
        <el-input v-model="Searchform.DocNo" style="width:262px;"></el-input>
      </el-form-item>
      <el-form-item label="标  题 ：" :label-width="formLabelWidth">
        <el-input v-model="Searchform.Title" style="width:262px;"></el-input>
      </el-form-item>
      <el-form-item label="状 态 ：" :label-width="formLabelWidth">
        <el-select v-model="Searchform.DocStatus" style="width:262px;" placeholder="请选择">
          <el-option value="" label="全部">全部</el-option>
          <el-option
            v-for="item in StatusOptions"
            :key="item.Code"
            :label="item.Name"
            :value="item.Code">
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer cover">
      <el-button size="small" @click="Reset">重 置</el-button>
      <el-button size="small" @click="Query">确 定</el-button>
      <el-button size="small" @click="dialogSearchVisible = false">取 消</el-button>
    </div>
  </el-dialog>
</section>
</template>

<script>
import moment from 'moment';
export default {
  name: "borrowMoney",
  data() {
    return {
      viewer: null, //viewer对象
      showNum: "", //传过来的参数
      key: "",
      total: 0, //数据总数
      rows: 100, //每页显示多少条
      currentPage: 1,//当前页数
      loading: true, //显示列表loading
      PrintLoading: true, //显示打印loading
      docViewloading: true, //查看流程弹窗
      dialogSearchVisible:false,//查询窗口
      formLabelWidth:'120px',
      StatusOptions:[],//状态列表
      DocNo: "", //单据编号
      isFirst:true,
      Msg: "", //审核提醒
      docView: [], //流程图列表
      printsData: {
        entity: {
          BorrowLineSet: []
        }
      }, //打印的数据
      launchObjectList: [],
      launch: [],
      UploadList: [], //附件列表数据
      launchAllow: false,
      content: "",
      IdArray: [],
      Type: 0, //0添加  1修改 2查看  3待
      supplierSelect: "",
      BorrowLine_YBL: "", //获取费用类型的ID
      rcvBankAccount: "", //银行账号
      rcvBank: "", //开户银行
      Borrow_Title: "", //描述
      Borrow_DocDate: "", //日期
      TotalBorrowMoney: "", //申请金额
      isshowAdd: false, //新建页面显隐
      isshowEdit: false, //编辑页面显隐
      isshowList: true, //table表单显隐
      borrowList: [], // 借款单列表
      selecSupplier: [], //获取供应商
      /* borrowDetail: [], //借款单详细信息 */
      bankInfo: [], //获取供应商银行信息
      bears: [], //获取费用承担部门数据
      detailTemp: [], //获取借款单明细
      supplierRadio: 0, //获取点击的名字
      Budget: [], //预算明细参数
      activeName: "first",
      checkflowRowVisible: false, //外面的流程图
      checkflowVisible: false, //里面的流程图
      budgetVisible: false, //超预算调整
      dialogPrintVisible: false, //打印窗口
      dialogUploadVisible: false, //上传窗口
      detail: [
        {
          BorrowLine_BorrowMoney: "", //金额
          YBL_Department: "", //费用承担部门
          BorrowLine_YBL: "", //费用类型
          balance: "", //预算金额
          costTypes: [] // 费用数据 。 提交保存时候不用传
        }
      ],
      BorrowLine_BorrowMoney: "", //报销明细--金额
      docView: [], //里面流程图列表
      docRowView: [], //外面流程图列表
      /**超预算 */
      abstract1: "", //追加理由
      abstract2: "", //互调预算追加理由
      fjBtnDisabled: true,
      Json: [],
      file: "",
      label: "",
      budgetSelect: [],
      Searchform: {
          StartMoney:0,
          EndMoney:0,
          StartDate:'',
          EndDate:'',
          DocNo:'',
          Title:'',
          DocStatus:''
      },
      budgetMoney: 0,
      templ: [],
      radio: 1,
      budgetitem: [],
      username: "",
      name: "",
      supplierSelectTemp: "",
      SFBudgetItem: true,
      //沟通模块
      dialogCommunicationVisible: false, //沟通窗口
      CommunicationContentList: [], //沟通内容列表
      contentInput: "", //输入内容Model
      acquiescenceImg: "static/content/images/Header-S.png", //默认头像
      LaunchList: [], //沟通对象集合
      launch: [], //沟通对象
      launchChecked: false, //是否允许编辑
      requestEmp: "", //申请人ID
      communiTypes: 0, //获取沟通状态
      isshowLauch: false,
      DocType: 302, //单据类型 报销单=301 借款单=302  还款单=303 收入确认单=304  出纳付款=401  出纳收款=402
      fileList: [],
      isShowSupplierSelect:false,//供应商显示隐藏
      mouse_enter_Borrow_DocNO:"",//鼠标移入当前行的单号
      communicateButtonDisabled:false,//沟通按钮是否置灰
    };
  },
  watch:{
    supplierRadio(curVal,oldVal){//切换收款对方时，显示下拉框 0：初始值 2：第一个值 1：第二个值
      // if(this.supplierRadio==1){
      //   console.log('我触发了它');
      //   this.doClickBtn();
      // }
      if (oldVal==2&&curVal==1) {
        this.isShowSupplierSelect=true
      }
      if (oldVal==1&&curVal==2) {
        this.isShowSupplierSelect=false
      }      
    },
    supplierSelect(curVal,oldVal){//切换收款对方时，改变下拉框内容
      // if(curVal!=""&&this.supplierRadio==1){//下拉框值：--》有
      //   this.doClickBtn();
      // }
      if(curVal!=""&&this.supplierRadio==1){
        this.isShowSupplierSelect=false
      }      
    }
  },
  methods: {
    // doClickBtn(){//点击"收款对方"弹窗按钮
    //   //document.getElementById("supplierRadioTwo").click();
    //   this.$refs.supplierRadioTwo.$el.click();
    // },
    cellMouseEnterFn(...arr){//鼠标移速单元格触发事件
      this.mouse_enter_Borrow_DocNO=arr[0].Borrow_DocNO
    },
    cellMouseLeaveFn(){
      this.mouse_enter_Borrow_DocNO=""
    },
    showDropDial(){//通过改变radio的值，触发watch,从而显示下拉框
      this.isShowSupplierSelect=true;
      if(this.supplierRadio==1){
        this.supplierRadio=0;
        setTimeout(()=>{this.supplierRadio=1},100)
      }
    },
    /* 时间过滤器 */
    formatDate(row, column) {
      return row.Borrow_DocDate.split("T", 1);
    },
    formatUploadDate(row, column) {
      return row.Attachment_UploadDate.split("T", 1);
    },
    handleClick(tab, event) {
      this.label = tab.label;
    },
    changePage(page) {//当前页数
      this.currentPage = page;
      this.getList();
    },
    search(){
      this.dialogSearchVisible = true;
      this.getStatusList();
    },
    async getStatusList(){
      this.StatusOptions = await axios.get('getStatusList');
    },
    /**
     * 打印
     */
    printPdf() {
      $("#form1").jqprint({
        debug: false,
        importCSS: true,
        printContainer: false,
        operaSupport: false
      });
    },
    /**
     * 选择业务类型
     */
    checkRadio(value) {
      //添加或编辑来控制这些数据
      if(!this.isFirst) {
        this.isFirst = true;
        return; 
      }
      if (this.isshowAdd === true && this.isshowEdit === false) {
        //如果是新增页面
        this.supplierRadio = "";
        this.supplierSelect = "";
        this.rcvBank = "";
        this.rcvBankAccount = "";
        this.supplierRadio = value; //value是选取的数值 1、2
        if (this.supplierRadio === 1) {
          //如果是其他供应商 获取供应商接口并且默认第一个
          axios
            .get("getSupplier", {
              Type: this.supplierRadio,
              T: this.Type
            })
            .then(res => {
              this.selecSupplier = res;
              /* this.supplierSelect = res[0].Code; */
              this.Bank();
            });
        } else if (this.supplierRadio===2){
          this.Supplier(); //获取供应商
        }
        return;
      }
      // 编辑页面
      if (this.isshowAdd === false && this.isshowEdit === true) {
        if (this.supplierRadio === 1) {
          axios
            .get("getSupplier", {
              Type: this.supplierRadio,
              T: this.Type
            })
            .then(res => {
              this.selecSupplier = res;
              this.supplierSelect = '';
              this.rcvBank = '';
              this.rcvBankAccount = ''
            });
        } else if(this.supplierRadio===2){
          this.Supplier(); //获取供应商
        }
      }
    },
    /**
     * 从供应商选择中获取银行信息
     */
    choiceSupplie(value) {
      this.Bank(); //获取供应商  带动开户银行和银行卡号 自动选择
    },
    /**
     * 新增-保存
     */
    addSave() {
      let myArr = [];
      //过滤掉有空的数据的那行
      //console.log(this.detail,"this.detail")
      if (this.detail.length>1) {
        this.detail=this.detail.filter((item)=>{
          return (item.BorrowLine_BorrowMoney||item.BorrowLine_YBL||item.YBL_Department)
        })
      }
      if (this.detail.length==0) {
        this.addlist();
      }
      let detail = this.detail;
      detail.forEach(value => {
        let money = value.BorrowLine_BorrowMoney; //金额
        let ybl = value.BorrowLine_YBL; //费用类型
        let temp = `{"Money":${money},"BLID":"${ybl}"}`;
        myArr.push(temp);
      });
      this.Budget = myArr.join(","); //逗号分割并拼接备份给json字符串传参
      this.Budget = `[` + this.Budget + `]`;
      let params = {
        Borrow_BusinessType: this.supplierRadio, //业务类型
        Borrow_Supplier: this.supplierSelect, //供应商
        Borrow_DocDate: this.Borrow_DocDate, //日期
        Borrow_RcvBankAccount: this.rcvBankAccount, //银行账号
        Borrow_RcvBank: this.rcvBank, //开户用户
        Borrow_Title: this.Borrow_Title, //业务描述
        Borrow_TotalBorrowMoney: this.TotalBorrowMoney, //申请金额
        Borrow_DocStatus: 1, //提交类型 1.保存 2.提交
        Budget: this.Budget, //预算明细
        key:this.DocNo
      };
      axios
        .post("submitBorrow", params)
        .then(res => {
          if (res.Success == true) {
            this.$message({
              message: `保存成功`,
              type: "success",
              duration: 1200
            });
            if(res.data.DocNO){
              this.DocNo = res.data.DocNO;
            }
          } else {
            this.$message({
              message: res.Message,
              type: "warning",
              duration: 1500
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    /**
     * 新增-提交
     */
    addSubmit() {
      let myArr = [];
      //过滤掉有空的数据的那行
      //console.log(this.detail,"this.detail")
      if (this.detail.length>1) {
        this.detail=this.detail.filter((item)=>{
          return (item.BorrowLine_BorrowMoney||item.BorrowLine_YBL||item.YBL_Department)
        })
      }
      if (this.detail.length==0) {
        this.addlist();
      }    
      let detail = this.detail;  
      detail.forEach(value => {
        let money = value.BorrowLine_BorrowMoney; //金额
        let ybl = value.BorrowLine_YBL; //费用类型
        let temp = `{"Money":${money},"BLID":"${ybl}"}`;
        myArr.push(temp);
      });
      this.Budget = myArr.join(","); //逗号分割并拼接备份给json字符串传参
      this.Budget = `[` + this.Budget + `]`;
      let params = {
        Borrow_BusinessType: this.supplierRadio, //业务类型
        Borrow_Supplier: this.supplierSelect, //供应商
        Borrow_DocDate: this.Borrow_DocDate, //日期
        Borrow_RcvBankAccount: this.rcvBankAccount, //银行账号
        Borrow_RcvBank: this.rcvBank, //开户银行
        Borrow_Title: this.Borrow_Title, //业务描述
        Borrow_TotalBorrowMoney: this.TotalBorrowMoney, //申请金额
        Borrow_DocStatus: 2, //提交类型 1.保存 2.提交
        Budget: this.Budget, //预算明细
        key:this.DocNo
      };
      axios
        .post("submitBorrow", params)
        .then(res => {
          if (res.Success == true) {
            this.$message({
              message: `提交成功`,
              type: "success",
              duration: 1200
            });
            if(res.data.DocNO){
              this.DocNo = res.data.DocNO;
            }
            this.isshowEdit = false;
            this.isshowAdd = false;
            this.isshowList = true;
            this.getList();
          } else if (res.Success == false && res.Message === "1") {
            this.budgetVisible = true;
            this.budgetMoney = 0;
            this.Json = res.data;
            this.DocNo = res.data[0].DocNO;
            this.Json.forEach(e => {
              this.budgetMoney += Number(e.Money);
              this.budgetMoney = this.budgetMoney;
            });
            this.getBudget();
          } else {
            this.$message({
              message: res.Message,
              type: "warning",
              duration: 1500
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },

    /**
     * 编辑-保存
     */
    editSave() {
      let myArr = [];
      let detail = this.detail;
      //过滤掉有空的数据的那行
      //console.log(this.detail,"this.detail")
      if (this.detail.length>1) {
        this.detail=this.detail.filter((item)=>{
          return (item.BorrowLine_BorrowMoney||item.BorrowLine_YBL||item.YBL_Department)
        })
      }
      if (this.detail.length==0) {
        this.addlist();
      }      
      detail.forEach(value => {
        let money = value.BorrowLine_BorrowMoney; //金额
        let ybl = value.BorrowLine_YBL; //费用类型
        let temp = `{"Money":${money},"BLID":"${ybl}"}`;
        myArr.push(temp);
      });
      this.Budget = myArr.join(","); //逗号分割并拼接备份给json字符串传参
      this.Budget = `[` + this.Budget + `]`;
      let params = {
        Borrow_BusinessType: this.supplierRadio, //业务类型
        Borrow_Supplier: this.supplierSelect, //供应商
        Borrow_DocDate: this.Borrow_DocDate, //日期
        Borrow_RcvBankAccount: this.rcvBankAccount, //银行账号
        Borrow_RcvBank: this.rcvBank, //开户用户
        Borrow_Title: this.Borrow_Title, //业务描述
        Borrow_TotalBorrowMoney: this.TotalBorrowMoney, //申请金额
        key: this.DocNo,
        Borrow_DocStatus: 1, //提交类型 1.保存 2.提交
        Budget: this.Budget //预算明细
      };
      axios
        .post("submitBorrow", params)
        .then(res => {
          if (res.Success == true) {
            this.$message({
              message: res.Message,
              type: "success",
              duration: 1200
            });
          } else {
            this.$message({
              message: res.Message,
              type: "warning",
              duration: 1500
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },

    /**
     * 编辑-提交
     */
    editSubmitForm() {
      let myArr = [];
      //过滤掉有空的数据的那行
      //console.log(this.detail,"this.detail")
      if (this.detail.length>1) {
        this.detail=this.detail.filter((item)=>{
          return (item.BorrowLine_BorrowMoney||item.BorrowLine_YBL||item.YBL_Department)
        })
      }
      if (this.detail.length==0) {
        this.addlist();
      }   
      let detail = this.detail;   
      detail.forEach(value => {
        let money = value.BorrowLine_BorrowMoney; //金额
        let ybl = value.BorrowLine_YBL; //费用类型
        let temp = `{"Money":${money},"BLID":"${ybl}"}`;
        myArr.push(temp);
      });
      this.Budget = myArr.join(","); //逗号分割并拼接备份给json字符串传参
      this.Budget = `[` + this.Budget + `]`;
      let params = {
        Borrow_BusinessType: this.supplierRadio, //业务类型
        Borrow_Supplier: this.supplierSelect, //供应商
        Borrow_DocDate: this.Borrow_DocDate, //日期
        Borrow_RcvBankAccount: this.rcvBankAccount, //银行账号
        Borrow_RcvBank: this.rcvBank, //开户银行
        Borrow_Title: this.Borrow_Title, //业务描述
        Borrow_TotalBorrowMoney: this.TotalBorrowMoney, //申请金额
        key: this.DocNo,
        Borrow_DocStatus: 2, //提交类型 1.保存 2.提交
        Budget: this.Budget
      };
      axios
        .post("submitBorrow", params)
        .then(res => {
          if (res.Success == true) {
            this.$message({
              message: res.Message,
              type: "success",
              duration: 800
            });
            this.isshowEdit = false;
            this.isshowAdd = false;
            this.isshowList = true;
            this.getList();
          } else if (res.Success == false && res.Message === "1") {
            this.budgetVisible = true;
            this.budgetMoney = 0;
            this.Json = res.data;
            this.Json.forEach(e => {
              this.budgetMoney += Number(e.Money);
              this.budgetMoney = this.budgetMoney;
            });
            this.getBudget();
          } else {
            this.$message({
              message: res.Message,
              type: "warning",
              duration: 1500
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    validationFn(){//验证提交表格是否出错
      let myArr = [];
      //过滤掉有空的数据的那行
      //console.log(this.detail,"this.detail")
      if (this.detail.length>1) {
        this.detail=this.detail.filter((item)=>{
          return (item.BorrowLine_BorrowMoney||item.BorrowLine_YBL||item.YBL_Department)
        })
      }
      if (this.detail.length==0) {
        this.addlist();
      }   
      let detail = this.detail;   
      detail.forEach(value => {
        let money = value.BorrowLine_BorrowMoney; //金额
        let ybl = value.BorrowLine_YBL; //费用类型
        let temp = `{"Money":${money},"BLID":"${ybl}"}`;
        myArr.push(temp);
      });
      this.Budget = myArr.join(","); //逗号分割并拼接备份给json字符串传参
      this.Budget = `[` + this.Budget + `]`;
      let params = {
        Borrow_BusinessType: this.supplierRadio, //业务类型
        Borrow_Supplier: this.supplierSelect, //供应商
        Borrow_DocDate: this.Borrow_DocDate, //日期
        Borrow_RcvBankAccount: this.rcvBankAccount, //银行账号
        Borrow_RcvBank: this.rcvBank, //开户银行
        Borrow_Title: this.Borrow_Title, //业务描述
        Borrow_TotalBorrowMoney: this.TotalBorrowMoney, //申请金额
        key: this.DocNo,
        Borrow_DocStatus: 2, //提交类型 1.保存 2.提交
        Budget: this.Budget
      };
      let That=this;
      return new Promise(function(resolve,reject){
        axios.get('erBorrowVerification', params).then(res=>{
          if (res.Success == true) {
            resolve()
          } else {
            That.$message({
              message: res.Message,
              type: "warning",
              duration:1500              
            });
          }
        }).catch(err=>{
          console.log(err,"err")
        });
      })

    },
    // editSubmit() {
    //   this.getState();
    //   if (this.communiTypes === 2) {
    //     this.isshowLauch = true;
    //     this.dialogCommunicationVisible = true;
    //   } else {
    //     this.editSubmitForm();
    //   }
    // },
    editSubmit() {
      this.validationFn().then(res=>{
        this.getState();
        if (this.communiTypes === 2) {
          this.isshowLauch = true;
          this.dialogCommunicationVisible = true;
        } else {
          this.editSubmitForm();
        }
      })
    },

    // 撤销
    repeal(index, row) {
      this.$confirm("确认撤销吗?", "提示", {
        type: "warning"
      }).then(() => {
        axios
          .get("revokeBorrow", {
            key: row.Borrow_DocNO
          })
          .then(res => {
            this.$message({
              message: res.Message,
              type: "success"
            });
            this.getList();
          });
      });
    },

    /**
     * 显示新增界面	
     */
    handleAdd() {
      this.isshowAdd = true; //新建页面显示
      this.isshowList = false; //列表页面隐藏
      this.isshowEdit = false; //编辑页面隐藏
      this.Borrow_DocDate = new Date();
      this.supplierRadio = 2;
      /**
       * 打开新增页面时顺便清空下数据
       */
      this.TotalBorrowMoney = "";
      this.Borrow_Title = "";
      this.DocNo = "";
      this.detail = [
        {
          BorrowLine_BorrowMoney: "",
          BorrowLine_YBL: "",
          YBL_Department: "",
          balance: ""
        }
      ];
      this.Type = 0;
      axios.get("getBorrowEmployee", {
          SupplierCode: ""
      }).then(res => {
          this.name = res[0].Name;
      }).catch(err => {
          console.log(err);
      });
      // 显示新增页面 获取 供应商信息
      this.Supplier();
    },

    // 添加行
    handleCurrentChange(val) {
      this.currentRow = val++;
    },
    /**
     * 预算明细添加行
     */
    addlist() {
      this.detail.push({
        BorrowLine_BorrowMoney: "",
        YBL_Department: "",
        BorrowLine_YBL: "",
        balance: "",
        costTypes: [] // 费用类型 数据
      });
    },

    //删除
    handleDel(index, row) {
      this.$confirm("确认删除该记录吗?", "提示", {
        type: "warning"
      }).then(() => {
        axios
          .get("deleBorrow", {
            key: row.Borrow_DocNO
          })
          .then(res => {
            this.$message({
              message: res.Message,
              type: "success"
            });
            this.getList();
          });
      });
    },
    /*
     *  查询 
     */
    async Query(){
      if(new Date(this.Searchform.StartDate)>new Date(this.Searchform.EndDate)){
        console.log(new Date(this.Searchform.StartDate),'this.Searchform.StartDate')
        console.log(new Date(this.Searchform.EndDate),'this.Searchform.EndDate')
        this.$message({
          message: '开始日期必须小于或者等于结束时期！',
          type: 'warning',
          duration: 1200
        });
        return;
      }else if(this.Searchform.StartMoney>this.Searchform.EndMoney){
        this.$message({
          message: '开始金额必须小于或者等于结束金额！',
          type: 'warning',
          duration: 1200
        });
        return;
      }
      this.dialogSearchVisible = false;
      console.log(this.Searchform.StartDate ? moment(this.Searchform.StartDate).format('L') : '','1');
      console.log(this.Searchform.EndDate ? moment(this.Searchform.EndDate).add(1,"d").format('L') : '','2');
      let filterName = {
        "groupOp": "AND",
        "rules": [{
          "field": "Borrow_DocNO",
          "dataType": "string",
          "op": "cn",
          "data": this.Searchform.DocNo || ''
        }, {
          "field": "Borrow_Title",
          "dataType": "string",
          "op": "cn",
          "data": this.Searchform.Title || ''
        },{
          "field": "Borrow_DocStatus",
          "dataType": "numeric",
          "op": "eq",
          "data": this.Searchform.DocStatus || ''
        }, {
          "field": "Borrow_TotalBorrowMoney",
          "dataType": "numeric",
          "op": "ge",
          "data": this.Searchform.StartMoney || ''
        }, {
          "field": "Borrow_TotalBorrowMoney",
          "dataType": "numeric",
          "op": "le",
          "data": this.Searchform.EndMoney || ''
        }, {
          "field": "Borrow_DocDate",
          "dataType": "string",
          "op": "ge",
          "data": this.Searchform.StartDate ? moment(this.Searchform.StartDate).format('L') : ''
        }, {
          "field": "Borrow_DocDate",
          "dataType": "string",
          "op": "le",
          "data": this.Searchform.EndDate ? moment(this.Searchform.EndDate).add(1,"d").format('L') : ''
        }],
        "groups": []
      }
      this.loading = true;
      const res = await axios.post("getBorrowList", { 
        filter:JSON.stringify(filterName),
        page:this.currentPage,
        rows:this.rows,
      });
      this.total = res.total;//总页数
      this.borrowList = res.rows;
      this.loading = false;
    },
    Reset(){
      this.Searchform = {
          StartMoney:0,
          EndMoney:0,
          StartDate:'',
          EndDate:'',
          DocNo:'',
          Title:'',
          DocStatus:''
      }
    },
    // 明细部分删除按钮
    handleDelete(index) {
      this.$confirm("确认删除该记录吗?", "提示", {
        type: "warning"
      }).then(() => {
        this.detail.splice(index, 1);
        if (this.detail.length==0) {//如果全部删除，默认留出一行空行
          this.addlist()
        }
        this.$message({
          message: "已删除",
          type: "success"
        });
      });
    },
    /*
     *	显示编辑界面
     */
    // handleEdit(index, row) {
    //   console.log(`index:${index},row:${row}`)
    handleEdit(...rest) {
      let row=rest[0];
      //wu退出新建页面，将收款对方恢复初始值
      this.supplierRadio=2;
      this.supplierSelect="";

      this.isFirst = false;
      if (!row) {
        this.showNum = this.$route.query.showNum;
        this.DocNo = this.$route.query.key;
      } else {
        this.DocNo = row.Borrow_DocNO;
      }
      this.isshowEdit = true; //编辑显示
      this.isshowList = false; //列表隐藏
      this.isshowAdd = false;
      // 获取借款单详细信息
      let all = [
        axios.get("BorrowDetail", {
          key: this.DocNo
        }),
        axios.get("BorrowItem", {
          key: this.DocNo
        })
      ];
      this.axios.all(all).then(
        this.axios.spread((res1, res2) => {
          /* this.borrowDetail = res1.entity; */
          this.communiTypes = res1.AllowCommunication; //获得沟通对象
          this.TotalBorrowMoney = res1.entity.Borrow_TotalBorrowMoney.toFixed(2);
          this.Borrow_DocDate = res1.entity.Borrow_DocDate;//日期
          this.Borrow_Title = res1.entity.Borrow_Title;//日期
          console.log(this.TotalBorrowMoney,'this.TotalBorrowMoney');
          console.log(this.Borrow_DocDate,'this.Borrow_DocDate');
          this.supplierRadio = res1.entity.Borrow_BusinessType; //业务类型
          if(this.supplierRadio==2){//收款对方，本人
            this.isFirst=true
          }           
          this.rcvBankAccount = res1.entity.Borrow_RcvBankAccount; //开户银行账号
          this.rcvBank = res1.entity.Borrow_RcvBank; //开户银行
          this.DocNo = res1.entity.Borrow_DocNO; //单据编号
          this.Type = res1.Type;
          //this.fjBtnDisabled = res1.FJNum==0?true:false;
          if (this.Type==1) {//修改状态附件按键亮起
            this.fjBtnDisabled=false;
          }else{//查看和待审核状态，有附件数才亮起
            this.fjBtnDisabled = res1.FJNum==0?true:false;
          }
          //获取对私供应商
          this.username = res1.entity.Borrow_CreateBy;
          axios
            .get("getBorrowEmployee", {
              SupplierCode: this.username
            })
            .then(res => {
              this.name = res[0].Name;
            })
            .catch(err => {
              console.log(err);
            });

          this.selecSupplier = [];
          axios
            .get("getSupplier", {
              Type: this.supplierRadio, //根据radio不同  1.其他 2.对私 决定不同供应商
              T: this.Type
            })
            .then(res => {
              //将供应商数组先清空，避免数据重复,然后再进行赋值操作
              this.selecSupplier = res;
              if (this.supplierRadio === 2) {
                //如果是个人 就默认绑定第一个供应商
                this.supplierSelect = res1.entity.Borrow_Supplier;
              } else {
                this.supplierSelect = res1.entity.Borrow_Supplier;
              }
              this.Bank(); // 接着 获取银行信息
            });

          this.detailTemp = res2; //明细列表
          this.detail = [];
          let getCostTypePromiseAll = [];
          for (let i = 0; i < this.detailTemp.length; i++) {
            this.detail.push({
              ...this.detailTemp[i],
              balance: 0,
              costTypes: []
            });
            getCostTypePromiseAll.push(
              this.getCostType(
                this.detail[i].YBL_Department, // 部门id
                this.detail[i].BorrowLine_YBL //  明细id
              )
            );
          }
          this.SFBudgetItem = false;
          //  获取 费用类型
          Promise.all(getCostTypePromiseAll).then(resultArr => {
            // 循环
            for (let i = 0; i < this.detail.length; i++) {
              // 每条明细赋值费用类型数据
              this.detail[i].costTypes = resultArr[i];
              let yes = !1;
              let m = 0; // 费用
              //循环 判断 明细里面的费用类型是不是存在 。
              resultArr[i].map(item => {
                if (item.ID == this.detail[i].BorrowLine_YBL) {
                  yes = !0;
                  m = item.YBL_ThisLeaved;
                }
              });
              // 不存在 就取第一个
              if (!yes) {
                this.detail[i].BorrowLine_YBL = resultArr[i][0].ID;
                this.detail[i].balance = resultArr[i][0].YBL_ThisLeaved;
              } else {
                this.detail[i].balance = m;
              }
            }

            this.SFBudgetItem = true;
          });
          // //判断状态获取沟通
          // if (this.communiTypes == 1 || this.communiTypes == 2) {
          //   this.dialogCommunicationVisible = true;
          //   this.isshowLauch = false;
          //   let all = [
          //     axios.get("CommunicationContent", {
          //       key: this.DocNo,
          //       DocType: this.DocType
          //     }),
          //     axios.get("LaunchList", {
          //       key: this.DocNo,
          //       DocType: this.DocType
          //     })
          //   ];
          //   this.axios.all(all).then(
          //     this.axios.spread((res1, res2) => {
          //       this.CommunicationContentList = res1; //获得沟通内容
          //       for (var i = 0; i < this.CommunicationContentList.length; i++) {
          //         if (this.CommunicationContentList[i].Img == "") {
          //           //如果是空的
          //           const ac = this.acquiescenceImg;
          //           this.CommunicationContentList[i].Img = ac; //赋值默认头像
          //         }
          //       }
          //       this.requestEmp = res2.RequestEmp; //申请人ID
          //       this.LaunchList = res2.us; //获得沟通对象
          //     })
          //   );
          // }
          let This=this;             
          this.getMayHaveCommunicationFn({key:This.DocNo,DocType:This.DocType,type:this.Type}).then((res)=>{
            This.communicateButtonDisabled=false
            //判断状态获取沟通
            if (this.communiTypes == 1 || this.communiTypes == 2) {
              this.dialogCommunicationVisible = true;
              this.isshowLauch = false;
              let all = [
                axios.get("CommunicationContent", {
                  key: this.DocNo,
                  DocType: this.DocType
                }),
                axios.get("LaunchList", {
                  key: this.DocNo,
                  DocType: this.DocType
                })
              ];
              this.axios.all(all).then(
                this.axios.spread((res1, res2) => {
                  this.CommunicationContentList = res1; //获得沟通内容
                  for (var i = 0; i < this.CommunicationContentList.length; i++) {
                    if (this.CommunicationContentList[i].Img == "") {
                      //如果是空的
                      const ac = this.acquiescenceImg;
                      this.CommunicationContentList[i].Img = ac; //赋值默认头像
                    }
                  }
                  this.requestEmp = res2.RequestEmp; //申请人ID
                  this.LaunchList = res2.us; //获得沟通对象
                })
              );
            }     
          }).catch((err)=>{
            This.communicateButtonDisabled=true
          })
        })
      );
    },
    /**
     * @param index [当前行数]
     * @param id [选中的部门code]
     */
    changeSelect(index, id, event) {
      console.log(event,"event")
      if (event) return; //如果下拉展开就不执行后面的了
      if (this.Type === 0) {
        // 获取费用类型方法
        this.getCostType(id).then(res => {
          this.detail[index].costTypes = res; //0添加  1修改 2查看  3有审核权限

          // vue中对象属性改变视图不更新问题：先清空再赋值
          let detailTmp=this.detail;
          this.detail=[];
          this.detail=detailTmp

          this.detail[index].BorrowLine_YBL="";       
          /* if(this.Type!==2 && this.Type!==3) { */ 
          //this.detail[index].BorrowLine_YBL = res[0] ? res[0].ID : ""; // 这个设置还是没有显示费用类新 balance 先把费用清除掉了先
          /* } */
        });
        return;
      }
      if (this.Type === 1 && this.SFBudgetItem) {
        this.getCostType(id).then(res => {
          if (res != null) {
            this.detail[index].costTypes = res;
            // vue中对象属性改变视图不更新问题：先清空再赋值
            let detailTmp=this.detail;
            this.detail=[];
            this.detail=detailTmp

            this.detail[index].BorrowLine_YBL ="";   
            // if (this.Type !== 2 && this.Type !== 3) {
            //   //0添加  1修改 2查看  3有审核权限
            //   //this.detail[index].BorrowLine_YBL = res[0] ? res[0].ID : ""; // 这个设置还是没有显示费用类新 balance 先把费用清除掉了先
            // }
          }
        });
      }
    },
    /**
     * @param code [部门id]
     * @param YBLID 明细ID 
     * 
     */
    getCostType(code, YBLID) {
      let Borrow_DocDate = moment(this.Borrow_DocDate).format('YYYY-MM');
      if (this.SFBudgetItem) {  
        //费用类型
        var params = {
          id: code,
          BudgetType: 3, //3是借款 1是报销
          period: Borrow_DocDate,
          type: this.Type,
          YBLID: YBLID
          //1是新增或修改 2审核查看
        };
        return axios.post("getBudgetItem", params);
      }
      return null;
    },

    ChangeMoney(index) {
      //费用类型绑定 与 预算金额
      const BorrowLine_YBL = this.detail[index].BorrowLine_YBL; //费用类型ID
      this.detail[index].costTypes.map(
        item =>
          BorrowLine_YBL == item.ID
            ? (this.detail[index].balance = item.YBL_ThisLeaved)
            : ""
      );
    },
    // 新建返回到列表页面
    addToBack() {
      this.isshowAdd = false; //新建页面隐藏
      this.isshowList = true; //列表页面显示
      // //退出新建页面，将收款对方恢复初始值
      this.supplierRadio=2;
      this.supplierSelect="";      
      this.deleToback();
      this.getList();
    },
    //清空草稿的附件
    deleToback() {
      axios
        .get("deleUploadBack", {
          Attachment_DocType: this.DocType,
          Attachment_DocCode: 0
        })
        .then(res => {
          console.log(res, "res");
        })
        .catch(err => {
          console.log(err);
        });
    },
    //编辑页面显隐
    editToBack() {
      this.isshowEdit = false; //编辑页面隐藏
      this.isshowList = true; //列表页面显示
      //退出编辑页面，将收款对方还原
      this.supplierRadio=2;
      this.supplierSelect="";
      this.getList();
    },
    //获取借款单列表
    async getList() {
      this.loading = true;
      const res = await axios.get("getBorrowList",{
        page:this.currentPage,
        rows:this.rows,
      });
      this.total = res.total;//总页数
      this.borrowList = res.rows;
      this.loading = false;
    },
    //获取供应商
    Supplier() {
      axios
        .get("getSupplier", {
          Type: this.supplierRadio, //根据radio不同  1.其他 2.对私 决定不同供应商
          T: this.Type
        })
        .then(res => {
          this.selecSupplier = res;
          if (this.supplierRadio == 2) {
            //如果是个人 就默认绑定第一个供应商
            this.supplierSelect = res[0].Code;
            console.log(this.supplierSelect,'this.supplierSelect')
          }
          this.Bank();
        });
    },
    // 获取供应商银行信息
    Bank() {
      axios
        .get("getBank", {
          code: this.supplierSelect,
          type: this.supplierRadio
        })
        .then(res => {
          this.bankInfo = []; //将银行数组先清空，避免数据重复,然后再进行赋值操作
          this.bankInfo = res;
          if (!res[0]) {
            return false;
          }
          this.rcvBankAccount = res[0].BankAccount; // 设置默认银行卡号
          this.rcvBank = res[0].Bank; //设置默认开户银行
        });
    },
    //开户银行改变的时候
    bankChange(e) {
      //循环找出银行数组一致的对比code如果一样就赋值开户银行卡号
      this.bankInfo.forEach(item => {
        if (e == item.Code) this.rcvBankAccount = item.BankAccount;
      });
    },
    // 获取费用承担部门数据
    bear() {
      axios.get("getDept").then(res => {
        return (this.bears = res);
      });
    },
    //沟通窗口打开
    Communication() {
      this.dialogCommunicationVisible = true;
      this.isshowLauch = false;
      let all = [
        axios.get("CommunicationContent", {
          key: this.DocNo,
          DocType: this.DocType
        }),
        axios.get("LaunchList", {
          key: this.DocNo,
          DocType: this.DocType
        }),
        axios.get("getCommuniState", {
          key: this.DocNo,
          DocType: this.DocType,
          types: this.Type
        })
      ];
      this.axios.all(all).then(
        this.axios.spread((res1, res2, res3) => {
          this.CommunicationContentList = res1; //获得沟通内容
          for (var i = 0; i < this.CommunicationContentList.length; i++) {
            if (this.CommunicationContentList[i].Img == "") {
              //如果是空的
              const ac = this.acquiescenceImg;
              this.CommunicationContentList[i].Img = ac; //赋值默认头像
            }
          }
          this.requestEmp = res2.RequestEmp; //申请人ID
          this.LaunchList = res2.us; //获得沟通对象
          this.communiTypes = res3; //获取沟通状态
        })
      );
    },
    //允许提交者编辑单据Change事件
    launchChange(e) {
      if (e) {
        let bo = true;
        for (let i = 0; i < this.launch.length; i++) {
          if (this.launch[i] == this.requestEmp) bo = false;
        }
        if (bo) this.launch.push(this.requestEmp);
      }
    },
    //确认后提交
    CommunicationDetermine() {
      if (this.isshowLauch == true) {
        this.$confirm("回复沟通单据将会自动提交，不可再编辑!", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            this.Communicate();
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消"
            });
          });
      } else {
        this.Communicate();
      }
    },
    //沟通窗口 确定按钮
    Communicate() {
      let user = "";
      for (let i = 0; i < this.launch.length; i++) {
        user += i != 0 ? "," : "";
        user += this.launch[i];
      }
      axios
        .get("AddCommunicate", {
          key: this.DocNo,
          DocType: this.DocType,
          msg: this.contentInput,
          user: user,
          bj: this.launchChecked ? 1 : 0,
          type: this.communiTypes
        })
        .then(res => {
          if (res.Success === true) {
            if (this.isshowLauch == true) this.editSubmitForm();
            //获得沟通内容
            this.getContent();
            this.$message({
              message: res.Message,
              type: "success",
              duration: 1200
            });
            this.getState();
            this.contentInput = "";
          } else {
            this.$message({
              message: res.Message,
              type: "warning",
              duration: 1200
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    //获取内容
    getContent() {
      axios
        .get("CommunicationContent", {
          key: this.DocNo,
          DocType: this.DocType
        })
        .then(res => {
          this.CommunicationContentList = res;
          for (var i = 0; i < this.CommunicationContentList.length; i++) {
            if (this.CommunicationContentList[i].Img == "") {
              //如果是空的
              const ac = this.acquiescenceImg;
              this.CommunicationContentList[i].Img = ac; //赋值默认头像
            }
          }
        });
    },
    //获取type
    getState() {
      axios
        .get("getCommuniState", {
          key: this.DocNo,
          DocType: this.DocType,
          types: this.Type
        })
        .then(res => {
          this.communiTypes = res;
        })
        .catch(err => {
          console.log(err);
        });
    },
    //审核提示
    checkMsg() {
      axios
        .get("checkMsg")
        .then(res => {
          this.Msg = res;
        })
        .catch(err => {
          console.log(err);
        });
    },
    //驳回借款单提示
    rejectBorrow() {
      axios
        .get("ExamineCommunication", {
          key: this.DocNo,
          DocType: this.DocType
        })
        .then(res => {
          if (res.Data === "1") {
            this.$confirm(res.Message, "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
            })
              .then(() => {
                this.IsRejectBorrow();
              })
              .catch(() => {
                this.$message({
                  type: "info",
                  message: "已取消"
                });
              });
          } else this.IsRejectBorrow();
        })
        .catch(err => {
          console.log(err);
        });
    },
    //驳回借款单 操作
    IsRejectBorrow() {
      /* this.DocNo = getQueryParam("key"); */
      this.$prompt("请您输入驳回的理由", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消"
      })
        .then(({ value }) => {
          this.$message({
            type: "success",
            message: "你的驳回的理由是：" + value
          });
          axios
            .get("rejectBorrow", {
              key: this.DocNo,
              type: 1, //0审核 1驳回
              Reason: value
            })
            .then(res => {
              this.$message({
                message: res,
                type: "success"
              });
              setTimeout(() => {
                this.$router.push({
                  path: "notAudit"
                });
              }, 500);
            })
            .catch(err => {
              console.log(err);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消输入"
          });
        });
    },
    //审核借款单提示
    auditBorrow() {
      axios
        .get("ExamineCommunication", {
          key: this.DocNo,
          DocType: this.DocType
        })
        .then(res => {
          if (res.Data === "1") {
            this.$confirm(res.Message, "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
            })
              .then(() => {
                this.ToExamineBorrow();
              })
              .catch(() => {
                this.$message({
                  type: "info",
                  message: "已取消"
                });
              });
          } else if (res.Data === "2") {
            this.$message({
              type: "warning",
              message: res.Message,
              duration: 1500
            });
          } else this.ToExamineBorrow();
        })
        .catch(err => {
          console.log(err);
        });
    },
    //审核借款单 操作
    ToExamineBorrow() {
      this.checkMsg(); //审核提示
      this.$confirm(this.Msg, {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          axios
            .get("auditBorrow", {
              key: this.DocNo,
              type: 0 //0审核 1驳回
            })
            .then(res => {
              this.$message({
                type: "success",
                message: res
              });
              setTimeout(() => {
                this.$router.push({
                  path: "notAudit"
                });
              }, 500);
            })
            .catch(err => {
              console.log(err);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    //内部流程图
    checkflow() {
      this.checkflowVisible = true;
      this.docViewloading = true;
      axios
        .get("checkFlow", {
          DocNo: this.DocNo, //单据编号
          DocType: this.DocType //类型为借款单
        })
        .then(res => {
          this.docView = res;
          setTimeout(() => {
            this.docViewloading = false;
          }, 800);
        })
        .catch(err => {
          console.log(err);
        });
    },
    //外部流程图
    checkflowRow(index, rows) {
      this.checkflowRowVisible = true;
      let DocNo = rows.Borrow_DocNO;
      if (this.checkflowRowVisible == true) {
        if (rows.DocStatus == "新建") {
          //如果是新建状态就直接给个提示
          this.checkflowRowVisible = false;
          this.$message({
            message: "新建状态未有流程图",
            type: "warning"
          });
        } else if (rows.DocStatus == "无效") {
          //如果是无效状态也直接给个提示
          this.checkflowRowVisible = false;
          this.$message({
            message: "未找到相对应的流程图",
            type: "warning"
          });
        } else {
          //否则直接请求拿列表数据
          this.docViewloading = true;
          axios
            .get("checkFlow", {
              DocNo: DocNo, //单据编号
              DocType: this.DocType //类型为借款单
            })
            .then(res => {
              this.docRowView = res;
              setTimeout(() => {
                this.docViewloading = false;
              }, 800);
            })
            .catch(err => {
              console.log(err);
            });
        }
      }
    },
    /**
     * 追加预算
     */
    Supplementarybudget() {
      if (
        this.abstract1 === "" ||
        this.abstract1 === null ||
        this.abstract1 === undefined
      ) {
        this.$message({
          message: "追加理由不能留空",
          type: "warning",
          duration: 1200
        });
      } else {
        let arr = [];
        let Json = this.Json;
        let docNo = Json[0].DocNO;
        Json.forEach(value => {
          let money = value.Money; //金额
          let id = value.ID; //明细ID
          let temp = `{"ID":"${id}","Money":"${money}","Type":"0","Value":"0"}`;
          arr.push(temp);
        });
        let budget = arr.join(","); //逗号分割并拼接备份给json字符串传参
        budget = `[` + budget + `]`;
        const params = {
          DocNo: docNo, //单据编号
          DocType: this.DocType, //this.DocType类型为借款单
          Abstract: this.abstract1, //追加理由
          Json: budget
        };
        axios
          .get("BorrowAdjust", params)
          .then(res => {
            if (res == "") {
              this.$message({
                message:
                  `系统会自动产生预算` + this.label + `申请,待预算调整审核通过后,您这张借款单会被自动提交`,
                type: "success",
                duration: 1200
              });
              this.budgetVisible = false;
              this.abstract1 = "";
              this.isshowEdit = false;
              this.isshowAdd = false;
              this.isshowList = true;
              this.getList();
            }
          })
          .catch(err => {
            console.log(err);
          });
      }
    },
    /**
     * 互调预算
     */
    Intermodulationbudget() {
      if (
        this.abstract2 === "" ||
        this.abstract2 === null ||
        this.abstract2 === undefined
      ) {
        this.$message({
          message: "互调预算不能留空",
          type: "warning",
          duration: 1200
        });
      } else {
        let arr = [];
        let Json = this.Json;
        let docNo = Json[0].DocNO;
        let budgetSelect = this.budgetSelect;
        let i = 0,
          templ = this.templ,
          temLength = templ.length;
        for (; i < temLength; i++) {
          let radio = templ[i].radio;
          let money = Json[i].Money;
          let id = Json[i].ID;
          let budgetSelect = this.budgetSelect[i];
          let temp = `{"ID":"${id}","Money":"${money}","Type":"${radio}","Value":"${budgetSelect}"}`;
          arr.push(temp);
        }
        let budget = arr.join(","); //逗号分割并拼接备份给json字符串传参
        budget = `[` + budget + `]`;
        const params = {
          DocNo: docNo, //单据编号
          DocType: this.DocType, //this.DocType类型为借款单
          Abstract: this.abstract2, //追加理由
          Json: budget
        };
        axios
          .get("BorrowAdjust", params)
          .then(res => {
            if (res == "") {
              this.$message({
                message:
                  `系统会自动产生预算` + this.label + `申请,待预算调整审核通过后,您这张借款单会被自动提交`,
                type: "success",
                duration: 1200
              });
              setTimeout(() => {
                this.budgetVisible = false;
                this.abstract2 = "";
                this.isshowEdit = false;
                this.isshowAdd = false;
                this.isshowList = true;
                this.getList();
              }, 1200);
            } else {
              this.$message({
                message: res,
                type: "error",
                duration: 1200
              });
            }
          })
          .catch(err => {
            console.log(err);
          });
      }
    },
    /**
     * 获得自动调整
     */
    getBudget() {
      let Json = this.Json;
      this.budgetSelect;
      this.templ = [];
      for (var i = 0; i < Json.length; i++) {
        let depart = Json[i].YBDEntity.DepartmentName; //部门
        let budget = Json[i].YBDEntity.BudgetItemName;
        let money = Json[i].Money;
        let str = `承担部门：${depart}	费用类型：${budget} 超支金额：${money}`;
        this.templ.push({
          radio: 1, //默认1
          trr: str,
          value: ""
        });
      }
      //打开窗口时 默认将月份第一个select选项为默认绑定
      axios.get("BorrowMonth").then(res => {
        this.templ.forEach(e => {
          if (res.length > 0) {
            //Month数据如果长度大于0
            e.value = res[0].ID; //设置默认第一个 月份Month 为radio第一个选项
          }
        });
      });
      //wuhongqing触发函数，请求月份数据
      this.budgetChangeRadio(1, 0)
    },
    /*
     * 超预算 改变Radio Change事件
     */
    budgetChangeRadio(e, index) {
      this.radio = e;
      if (e == 1) {
        //如果是选中第一个radio 请求月份数据
        axios
          .get("BorrowMonth")
          .then(res => {
            console.log(res,"res")
            this.budgetitem[index] = [];
            this.budgetitem[index] = res;
            console.log(this.templ[index], "this.templ[index]");
            if (this.budgetitem[index].length > 0) {
              this.templ[index].value = res[0].ID ? res[0].ID : res[0].Code;
            } else {
              this.templ[index].value = "";
            }
          })
          .catch(err => {
            console.log(err);
          });
      } else if (e == 2) {
        //如果是选中第二个radio 请求部门数据
        axios
          .get("BorrowDepartment", {
            Money: this.Json[index].Money,
            YBL_BudgetItem: this.Json[index].YBDEntity.BudgetItem,
            YBL_Year: this.Json[index].YBDEntity.Year,
            YBL_Month: this.Json[index].YBDEntity.Month,
            YBL_BudgetType: this.Json[index].YBDEntity.BudgetType
          })
          .then(res => {
            this.budgetitem[index] = [];
            this.budgetitem[index] = res;
            console.log(this.templ[index], "this.templ[index]");
            if (this.budgetitem[index].length > 0) {
              this.templ[index].value = res[0].ID ? res[0].ID : res[0].Code;
            } else {
              this.templ[index].value = "";
            }
          })
          .catch(err => {
            console.log(err);
          });
      } else if (e == 3) {
        //如果是选中第三个radio 请求科目数据
        axios
          .get("BorrowBudgetItem", {
            //科目
            Money: this.Json[index].Money,
            YBL_Department: this.Json[index].YBDEntity.Dept,
            YBL_YearBudget: this.Json[index].YBDEntity.YearBudget,
            YBL_Year: this.Json[index].YBDEntity.Year,
            YBL_Month: this.Json[index].YBDEntity.Month,
            YBL_BudgetType: this.Json[index].YBDEntity.BudgetType
          })
          .then(res => {
            this.budgetitem[index] = [];
            this.budgetitem[index] = res;
            if (this.budgetitem[index].length > 0) {
              this.templ[index].value = res[0].ID ? res[0].ID : res[0].Code;
            } else {
              this.templ[index].value = "";
            }
          })
          .catch(err => {
            console.log(err);
          });
      }
    },
    // 超预算-撤销
    repealBudget() {
      this.$confirm("确认撤销吗?", "提示", {
        type: "warning"
      }).then(() => {
        axios
          .get("revokeBorrow", {
            key: this.DocNo
          })
          .then(res => {
            this.$message({
              message: res.Message,
              type: "success",
              duration: 1200
            });
            this.budgetVisible = false;
            setTimeout(() => {
              this.isshowEdit = false;
              this.isshowAdd = false;
              this.isshowList = true;
              this.getList();
            }, 500);
          });
      });
    },
    budgetChangeSelect(index, e) {
      this.budgetSelect[index] = e;
    },
    //打印窗口
    async getPrint(){
      this.dialogPrintVisible = true;
      this.PrintLoading = true;
      const res = await axios.get("Print",{DocNo:this.DocNo,DocType: this.DocType});
      this.printsData = res;
      this.PrintLoading = false;      
    },
    budget() {
      this.budgetVisible = true;
    },
    //打开附件列表窗口
    openUploadDialog() {   
      this.dialogUploadVisible = true;
      this.getUploadList();
    },
    //附件列表
    async getUploadList() {
      const res = await axios.get('UploadList', {
        key: this.DocNo,
        type: this.DocType,
        page: 1, //一页
        rows: 5000 //显示5000条
      })
      this.UploadList = res.rows;
    },
    //删除附件
    async DeleUpload(index,row) {
      const res = await axios.get('deleUpload',{key:row.ID})
      if (res.Success) {
          this.$message({
            message: res.Message,
            type: "success"
          })
          this.getUploadList();
      }else{
          this.$message({
            message: res.Message,
            type: "error"
          })
      }
    },
    //判断是否显示预览按钮
    isShowPreview (name) {
      var fileType = ['gif','jpg','png','JPG','PNG'];
      var temp = name.substring(name.lastIndexOf('.')+1);
      if(fileType.indexOf(temp) > -1) {
        return true
      }else {
        return false
      }
    },
    //开始上传附件
    update(e) {
      for(var i=0 ;i < e.target.files.length;i++){
      let file = e.target.files[i];
      let param = new FormData(); //创建form对象
      param.append("fileData", file); //通过append向form对象添加数据
      param.append("chunk", "0"); //添加form表单中其他数据
      param.append("key", this.DocNo); //添加form表单中其他数据
      param.append("Type", this.DocType);
      console.log(param.get("file")); //FormData私有类对象，访问不到，可以通过get判断值是否传进去
      let config = {
        headers: {
          "Content-Type": "multipart/form-data"
        }
      }; //添加请求头
      axios
        .post("Upload", param, config)
        .then(res => {
          if (res.Success) {
            this.$message({
              message: `上传成功`,
              type: "success"
            });
          } else {
            this.$message({
              message: res.Message,
              type: "success"
            });
          }
          this.getUploadList();
        })
        .catch(err => {
          this.$message({
            message: `附件上传异常！`,
            type: "warning"
          });
        });
      }
    },
    preview(scoped) {
      if (this.viewer) {
        this.viewer.destroy();
      }
      this.viewer = new this.$Viewer(this.$refs["images"], {
        url: "src",
        toolbar: {
          zoomIn: {
            show: 4,
            size: "large"
          },
          zoomOut: {
            show: 4,
            size: "large"
          },
          prev: {
            show: 4,
            size: "large"
          },
          next: {
            show: 4,
            size: "large"
          },
          rotateLeft: {
            show: 4,
            size: "large"
          },
          rotateRight: {
            show: 4,
            size: "large"
          }
        }
      });
      this.$refs["images"].childNodes[scoped.$index].childNodes[0].click()
    }
  },
  mounted() {
    this.checkMsg(); //审核提示
    this.getList(); //初始借款单列表
    this.bear();
    if (this.$route.query.showNum && this.$route.query.key) {
      this.handleEdit();
    }
    if(this.$route.query.News){
      this.handleAdd();
    }
  },
  created() {
    setTimeout(() => {
       console.log(this.$refs["test"]);
    }, 6000);
   
  },
  computed:{
    Count(){
      let sum = 0;
      for (let i of this.detail){
        sum += Number(i.BorrowLine_BorrowMoney)
      }
      return sum.toFixed(2);
    },
    SupplyCodeToNameFn(){//
      if (this.supplierSelect) {
        for (let i = 0; i < this.selecSupplier.length; i++) {
          if(this.selecSupplier[i].Code===this.supplierSelect){
            return this.selecSupplier[i].Name
          }
        }
      }
    }     
  }
};
</script>

<style scoped lang="scss">
@import "../../common/css/index.css";
.toolbar h2 {
  line-height: 36px;
  margin: 0 10px 0 0;
}

.dele {
  margin: 0 auto;
  display: block;
}

</style>
